echo -e '增加自建站 Nginx 模块---开始\n'


cat > /etc/nginx/sites-available/mywebsite <<EOF
server {
	listen 8088;
	listen [::]:8088;
	server_name mv100;
	root /var/www/html/mv100;
	index index.php index.html;
	location / {
		try_files $uri $uri/ =404;

		rewrite ^/PLTV/8888/(.*)/(.*).m3u8(.*)$  /parse/live/$1/index.php?id=$2&playseek=$3 last;
		rewrite ^/TVOD/8888/(.*)/(.*).m3u8(.*)$  /parse/live/$1/index.php?id=$2&playseek=$3 last;
	}
	location ~ .*\.php(\/.*)*|.html$ {
		include snippets/fastcgi-php.conf;
		set $path_info "";
		set $real_script_name $fastcgi_script_name;
		if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
			set $real_script_name $1;
			set $path_info $2;
		}
		fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
		fastcgi_param SCRIPT_NAME $real_script_name;
		fastcgi_param PATH_INFO $path_info;
		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

	}
	include /etc/nginx/locations.d/*;
}
EOF

echo -e '增加自建站 Nginx 模块---结束\n'

echo -e '创建软链接\n'

ln -sf /etc/nginx/sites-{available,enabled}/mywebsite

echo -e '重启NGINX\n'
nginx -s reload